package com.levi.http.utils;

import java.io.File;
import java.net.FileNameMap;
import java.net.URLConnection;

import javax.activation.MimetypesFileTypeMap;

import okhttp3.MediaType;

/**
 * 文件media type适配器
 * Created by Levi on 17/3/8.
 */

public class FileMediaTypeParser {

    public static MediaType parse(File file) {
        String type = null;
//        try {
//            type = new MimetypesFileTypeMap().getContentType(file);
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
             type = fileNameMap.getContentTypeFor(file.getName());
//        } catch (Exception E) {
//            type = "image/jpeg";
//        }
        return MediaType.parse(type + "; charset=utf-8");
    }
}
